/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize) {
    int has[1001] = { 0 };
    *returnSize = 0;
    int max = nums1Size;
    if (nums2Size > nums1Size) {
        max = nums2Size;
    }
    int* ret = (int*)malloc(sizeof(int) * max);
    //
    for (int i = 0; i < nums1Size; i++) {
        has[nums1[i]]++;
    }
    for (int i = 0; i < nums2Size; i++) {
        if (has[nums2[i]] > 0) {
            ret[(*returnSize)++] = nums2[i];
            has[nums2[i]] = 0;
        }
    }
    return ret;
}